package singleton;


/**
 * @description:
 * @author: jhy
 * @time: 2021/4/22 22:12
 */
public class InnerClassSingletonSafeTest {
    public static void main(String[] args) {
        new Thread(()->{
            System.out.println(InnerClassSingletonSafe.getInstance());
        }).start();
        new Thread(()->{
            System.out.println(InnerClassSingletonSafe.getInstance());
        }).start();
    }
}

class InnerClassSingletonSafe{

    public static class SingletonHolder{
        private static InnerClassSingletonSafe instance = new InnerClassSingletonSafe();
    }

    //私有构造方法
    private InnerClassSingletonSafe(){

    }
    //提供一个公共访问节点，以获得该实例
    public static InnerClassSingletonSafe getInstance(){
        return SingletonHolder.instance;
    }
}
